package com.adcc.es;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class MainForm {

	protected Shell shell;
	private Text text;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			MainForm window = new MainForm();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(588, 455);
		shell.setText("SWT Application");
		
		text = new Text(shell, SWT.BORDER);
		text.setBounds(138, 20, 315, 109);
		
		Button btnNewButton = new Button(shell, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent arg0) {
//			Map map = save("song001","list001","",null);
			}
		});
		btnNewButton.setBounds(141, 178, 80, 27);
		btnNewButton.setText("\u65B0\u589E");
		
		Button btnNewButton_1 = new Button(shell, SWT.NONE);
		btnNewButton_1.setBounds(245, 178, 80, 27);
		btnNewButton_1.setText("\u4FEE\u6539");
		
		Button btnNewButton_2 = new Button(shell, SWT.NONE);
		btnNewButton_2.setBounds(355, 178, 80, 27);
		btnNewButton_2.setText("\u5220\u9664");
		
		Button btnNewButton_3 = new Button(shell, SWT.NONE);
		btnNewButton_3.setBounds(141, 231, 80, 27);
		btnNewButton_3.setText("\u67E5\u8BE2");

	}
//	/**
//	 * ������ݵ�Elasticsearch
//	 * @param index		����
//	 * @param type		����
//	 * @param idName	Id�ֶ�����
//	 * @param listData  һ�����󼯺�
//	 * @return
//	 */
//	@SuppressWarnings("unchecked")
//	public static  Map save(String index, String type, String idName,List listData) {
//		BulkRequestBuilder bulkRequest = ESTools.client.prepareBulk().setRefresh(true);
//		Map resultMap = new HashMap();
//
//		IndexRequestBuilder lrb = ESTools.client
//                                                         .prepareIndex(index, type,"6")
//                                                         .setSource("null");
//		bulkRequest.add(lrb);
////		for (Object object : listData) {
////			JSONObject json = JSONObject.fromObject(object);
////			//û��ָ��idName �Ǿ���Elasticsearch�Զ�����
////			if(StringUtils.isBlank(idName)){
////				IndexRequestBuilder lrb = ESTools.client
////                                                            .prepareIndex(index, type)
////                                                                .setSource(json);
////				bulkRequest.add(lrb);
////			}
////			else{
////				String idValue = json.optString(idName);
////				IndexRequestBuilder lrb = ESTools.client
////                                                                 .prepareIndex(index, type,idValue)
////                                                                 .setSource(json);
////				bulkRequest.add(lrb);
////			}
////
////		}
//		BulkResponse bulkResponse = bulkRequest.execute().actionGet();
//		if (bulkResponse.hasFailures()) {
//			// process failures by iterating through each bulk response item
//			System.out.println(bulkResponse.getItems().toString());
//			resultMap.put("500", "����ESʧ��!");
//			return resultMap;
//		}
//		bulkRequest = ESTools.client.prepareBulk();
//		resultMap.put("200", "����ES�ɹ�!");
//		return resultMap;
//	}
}
